package com.toro.utils;

import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @ClassName: MysqlConnetion
 * @Description:
 * @Author: ToroLHZ
 * @Date: 2023/12/17 14:06
 */
@Slf4j
public class MysqlConnection {
    public static Connection getConnection() {
        Connection connection = null;
        try {
            //1、将com.mysql.jdbc.Driver加载进内存，它的静态代码块会自动注册驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //2、提供连接数据库的必要信息
            String url = "jdbc:mysql://localhost:3307/netty_chat?useSSL=false&characterEncoding=utf-8&serverTimezone=Hongkong";
            String user = "root";
            String password = "123456";
            //获取连接
            connection = DriverManager.getConnection(url, user, password);
            System.out.println(connection);
        } catch (SQLException | ClassNotFoundException e) {
            log.error("数据库连接异常：{}", e.getMessage());
        }
        return connection;
    }


}
